package com.bclz.task.flowpartitioner;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.WritableComparable;

public class FlowObject implements WritableComparable<FlowObject> {
		
	
	private String phone;
	
	private Long upFlow;
	
	private Long downFlow;
	
	private Long flowSum;
	
	public FlowObject(){}
	
	public FlowObject(String phone,Long upFlow,Long downFlow){
		this.phone=phone;
		this.upFlow=upFlow;
		this.downFlow=downFlow;
		this.flowSum=upFlow+downFlow;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public Long getUpFlow() {
		return upFlow;
	}

	public void setUpFlow(Long upFlow) {
		this.upFlow = upFlow;
	}

	public Long getDownFlow() {
		return downFlow;
	}

	public void setDownFlow(Long downFlow) {
		this.downFlow = downFlow;
	}


	@Override
	public void write(DataOutput out) throws IOException {
		// TODO Auto-generated method stub
		out.writeUTF(this.phone);
		out.writeLong(this.downFlow);
		out.writeLong(this.upFlow);
	}

	@Override
	public void readFields(DataInput in) throws IOException {
		// TODO Auto-generated method stub
		this.phone=in.readUTF();
		this.downFlow=in.readLong();
		this.upFlow=in.readLong();
	}

	@Override
	public int compareTo(FlowObject o) {
		// TODO Auto-generated method stub
		
		return o.getPhone().compareTo(o.getPhone());
	}
	
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return String.format("手机号:%s,上行总流量:%s,下行总流量:%s,总流量:%s", this.phone,this.upFlow,this.downFlow,this.flowSum);
	}
	
	
}
